#include <iostream>
using namespace std;
class Person {
public:
    // 无参构造函数
    Person(): name("default") {
        cout << "Person() name: " << this->name << endl;
    }
    Person(const string& name) {
        this->name = name;
        cout << "Person(name) name: " << this->name << endl;
    }
    // 拷贝构造函数
    Person(const Person &p) {
        this->name = p.name;
        cout << "Person(Person&) name: " << this->name << endl;
    }
    // 析构函数
    ~Person() { cout << "~Person() name: " << this->name << endl; }
    // 重载赋值操作符
    Person& operator=(const Person &p) {
        this->name = p.name;
        cout << "Person::operator=" << this->name << endl;
        return *this;
    }
public:
    string name;
};

Person getNewPerson(const string& name) {
    Person p(name);
    return p;
} 

void test() {
    // 返回值用来初始化
    Person p1 = getNewPerson("Mango");
    cout << "test() end" << endl;
}

void test2() {
    Person p1;
    p1 = getNewPerson("Mango"); 
    p1.name = "Mango-p1";
    cout << "test2() end" << endl;
}

int main() {
    // test();
    test2();
    return 0;
}